#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main(){

//    int fd = open("log.txt", O_WRONLY | O_CREAT , 0666);            // 从头开始覆盖是写法！
//    int fd = open("log.txt", O_WRONLY | O_CREAT | O_TRUNC, 0666);   // 从头开始，先清空，再写入
    int fd = open("log.txt", O_WRONLY | O_CREAT | O_APPEND, 0666);  // 追加式写入

    if(fd < 0){
        perror("open()");
        exit(1);
    }

    const char* buf = "hello\n";

    write(fd, buf, strlen(buf));

    printf("write success! fd = %d\n", fd);

    close(fd);

    return 0;
}
